Find out the IP addresses if appeared more than 4times
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Help us to help you. Provide a sample input file (10-15 lines will do). Construct a sample output file which corresponds to your sample input and post both samples here. With "InFile" and "OutFile" examples we can better understand your needs and also judge if our proposed solution fills those needs.
ok, since awk is already involved:
1. do not use cat|grep|awk|sed|awk|sort chain, because it can be solved with a single awk
2. would be nice to see some lines of that log file
you can start with something like this:
Code:
awk -F']' '/after AUTH from/ { ip[$NF]++ }
END { for (i in ip) print "ip=" i ", ("ip[i]")" }'
Jul 14 17:31:31 mail postfix/smtpd[26111]: lost connection after AUTH from unknown[180.120.191.39]
Jul 14 17:31:34 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[180.125.131.77]
Jul 14 17:31:46 mail postfix/smtps/smtpd[25242]: lost connection after AUTH from unknown[45.13.39.115]
Jul 14 17:31:47 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[180.121.150.182]
Jul 14 17:31:54 mail postfix/smtpd[26111]: lost connection after AUTH from unknown[121.232.8.7]
Jul 14 17:31:59 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[114.232.217.208]
Jul 14 17:32:07 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[114.232.59.9]
Jul 14 17:32:13 mail postfix/smtpd[26111]: lost connection after AUTH from unknown[180.121.150.182]
Jul 14 17:32:15 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[49.79.137.34]
Jul 14 17:32:27 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[114.231.137.42]
Jul 14 17:32:36 mail postfix/smtps/smtpd[25242]: lost connection after AUTH from unknown[185.211.245.198]
Jul 14 17:32:44 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[117.86.178.209]
Jul 14 17:32:47 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[180.121.150.182]
Jul 14 17:32:50 mail postfix/smtpd[26111]: lost connection after AUTH from unknown[49.67.164.187]
Jul 14 17:32:50 mail postfix/smtps/smtpd[27984]: lost connection after AUTH from unknown[185.211.245.198]
Jul 14 17:33:06 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[121.232.17.128]
Jul 14 17:33:09 mail postfix/smtpd[26111]: lost connection after AUTH from unknown[180.121.141.252]
Jul 14 17:33:16 mail postfix/smtpd[1331]: lost connection after AUTH from unknown[121.226.92.32]
Jul 14 17:33:44 mail postfix/smtps/smtpd[28128]: lost connection after AUTH from unknown[45.13.39.115]
Jul 14 17:35:44 mail postfix/smtps/smtpd[25242]: lost connection after AUTH from unknown[45.13.39.115]
Jul 14 17:37:40 mail postfix/smtps/smtpd[28128]: lost connection after AUTH from unknown[45.13.39.115]
Jul 14 17:39:06 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[49.67.111.97]
Jul 14 17:39:06 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[49.67.64.36]
Jul 14 17:39:08 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[121.226.63.59]
Jul 14 17:39:10 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[114.232.217.184]
Jul 14 17:39:12 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[49.67.67.223]
Jul 14 17:39:12 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[121.232.16.38]
Jul 14 17:39:14 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[121.226.92.162]
Jul 14 17:39:15 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[180.125.131.49]
Jul 14 17:39:17 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[121.226.60.137]
Jul 14 17:39:18 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[114.231.141.167]
Jul 14 17:39:20 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[49.67.141.195]
Jul 14 17:39:21 mail postfix/smtps/smtpd[28128]: lost connection after AUTH from unknown[185.211.245.198]
Jul 14 17:39:22 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[180.121.148.113]
Jul 14 17:39:22 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[49.67.70.133]
Jul 14 17:39:23 mail postfix/smtpd[7126]: lost connection after AUTH from unknown[121.226.126.159]
Jul 14 17:39:24 mail postfix/smtpd[26115]: lost connection after AUTH from unknown[121.232.19.144]
awk -F'[][]' '/after AUTH from/ { ip[$(NF-1)]++ }
END { for (i in ip) print "ip=" i ", ("ip[i]")" }'
this will work, you need only to add the include/exclude filter
Add your condition like this.
Code:
awk -F'[][]' '/after AUTH from/ { ip[$(NF-1)]++ } END { for (i in ip) if (ip[i]>=4) print i,"("ip[i]")" }' /var/log/maillog
Explanations:
The -F is a character set of [ and ] so the 2nd last field $(NF-1) holds the ip.
Store a count in the array ip that is addressed by the $(NF-1).
At the END loop through the array and print if the condition is met.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.